<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:loc="clr-namespace:LockCrypt"
  xmlns:conv="clr-namespace:LockCrypt.Converters">

    <Style TargetType="{x:Type ListBox}" x:Key="{x:Type ListBox}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="BorderBrush" Value="{StaticResource btnPressStroke2}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Background" Value="#FFFFFFFF"/>
        <Setter Property="Foreground" Value="{StaticResource OutsideFontColor}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <Grid>
                        <Border BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="2">
                            <ScrollViewer Margin="1" Focusable="false" Background="{TemplateBinding Background}">
                                <StackPanel Margin="2" IsItemsHost="true"/>
                            </ScrollViewer>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false"/>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style TargetType="{x:Type ListBoxItem}" x:Key="{x:Type ListBoxItem}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="false"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="3" />
        <Setter Property="Foreground" Value="{StaticResource OutsideFontColor}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="HoverOn">
                            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientOver" Storyboard.TargetProperty="Opacity" To="0.73"/>
                        </Storyboard>
                        <Storyboard x:Key="HoverOff">
                            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientOver" Storyboard.TargetProperty="Opacity" To="0"/>
                        </Storyboard>
                        <Storyboard x:Key="SelectedOn">
                            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
                            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelectedDisabled" Storyboard.TargetProperty="Opacity" To="1"/>
                        </Storyboard>
                        <Storyboard x:Key="SelectedOff">
                            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
                            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelectedDisabled" Storyboard.TargetProperty="Opacity" To="0"/>
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid SnapsToDevicePixels="true">
                        <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2" Opacity="0"/>
                        <Rectangle x:Name="BackgroundGradientSelectedDisabled" Fill="{StaticResource grayGradient}" Stroke="#7F8E8F8F" RadiusX="2" RadiusY="2" Opacity="0"/>
                        <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0"/>
                        <Rectangle x:Name="BackgroundHighlight" Margin="1" Stroke="#A0FFFFFF" RadiusX="1" RadiusY="1"/>
                        <ContentPresenter
	                        	x:Name="contentPresenter"
	                        	Content="{TemplateBinding Content}"
	                        	ContentTemplate="{TemplateBinding ContentTemplate}"
	                        	HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
	                        	Margin="{TemplateBinding Padding}"/>
                    </Grid>
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsSelected" Value="true">
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource SelectedOff}" x:Name="SelectedOff_BeginStoryboard"/>
                            </Trigger.ExitActions>
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource SelectedOn}" x:Name="SelectedOn_BeginStoryboard"/>
                            </Trigger.EnterActions>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource HoverOff}" x:Name="HoverOff_BeginStoryboard"/>
                            </Trigger.ExitActions>
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HoverOn}"/>
                            </Trigger.EnterActions>
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                            <Setter Property="Visibility" TargetName="BackgroundGradientSelected" Value="Hidden"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="InvisibleListBoxItem" TargetType="{x:Type ListBoxItem}">
        <Setter Property="Background" Value="Transparent" />
    </Style>

    <Style x:Key="InvisibleListBox" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CheckBoxListTemplate" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="SelectionMode" Value="Extended" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Margin" Value="2" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Background="{TemplateBinding Background}">
                                    <ContentPresenter />
                                </CheckBox>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RadioListTemplate" TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="SelectionMode" Value="Single" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Margin" Value="2" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <RadioButton VerticalAlignment="Center" VerticalContentAlignment="Center" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}">
                                    <ContentPresenter VerticalAlignment="Center" />
                                </RadioButton>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="BulletedListBox" TargetType="{x:Type ListBox}">
        <Setter Property="IsEnabled" Value="True" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Margin" Value="20,2,2,2" />
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <ControlTemplate.Resources>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="TextWrapping" Value="Wrap"/>
                                        <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
                                    </Style>
                                </ControlTemplate.Resources>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="{TemplateBinding Background}">
                                    <!--Ellipse Fill="{StaticResource GlyphBrush}" Width="4" Height="4" Margin="0,0,5,0" VerticalAlignment="Center" /-->
                                    <Ellipse Fill="{TemplateBinding Foreground}" Width="4" Height="4" Margin="0,0,5,0" VerticalAlignment="Center" />
                                    <ContentPresenter VerticalAlignment="Center" TextBlock.Foreground="{TemplateBinding Foreground}"  />
                                </StackPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="BigLanguagesList" TargetType="{x:Type ListBox}">
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Margin" Value="2" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <!--WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top"
                               Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" /-->
                    <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Center"
                               Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="BorderBrush" Value="Transparent" />
                    <Setter Property="BorderThickness" Value="0" />
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Tag" Value="32" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <ControlTemplate.Resources>
                                    <conv:SizedImageConverter x:Key="IconConverter"/>
                                </ControlTemplate.Resources>
                                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
                                        Padding="3,0,3,0">
                                    <Grid HorizontalAlignment="Left" VerticalAlignment="Center"
                                          Height="40" Width="200">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="32"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Image Grid.Column="0" Width="32" Height="32" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center">
                                            <Image.Source>
                                                <MultiBinding Converter="{StaticResource IconConverter}" ConverterParameter="Images/Flags">
                                                    <!--Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Key"/-->
                                                    <Binding Path="Key"/>
                                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Tag"/>
                                                </MultiBinding>
                                            </Image.Source>
                                        </Image>
                                        <TextBlock Grid.Column="1" Margin="5,1,0,1" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Text="{Binding Value.EnglishName}" VerticalAlignment="Center" />
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="true">
                                        <Setter Property="BorderBrush" Value="Black"/>
                                        <Setter Property="Background" Value="{StaticResource BtnOverFill}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="IconListCell" TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
        <Setter Property="Width" Value="40" />
        <Setter Property="Height" Value="40" /><!-- width/height are the ListBoxItem size -->
        <Setter Property="Tag" Value="32"/><!-- tag is the image size -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <ControlTemplate.Resources>
                        <conv:IconConverter x:Key="IconConverter"/>
                    </ControlTemplate.Resources>
                    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Background="{TemplateBinding Background}" ToolTip="{Binding DataContext.Key,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                                Width="{TemplateBinding Width}" MaxWidth="{TemplateBinding Width}"
                                Height="{TemplateBinding Height}" MaxHeight="{TemplateBinding Height}"> 
                        <Image Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Width="{Binding Tag,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" Height="{Binding Tag,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}">
                            <Image.Source>
                                <MultiBinding Converter="{StaticResource IconConverter}">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="DataContext.Key"/>
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Tag"/>
                                </MultiBinding>
                            </Image.Source>
                        </Image>
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="BorderBrush" Value="Black"/>
                            <Setter Property="Background" Value="{StaticResource BtnOverFill}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="LargeIconList" TargetType="{x:Type ListBox}">
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Margin" Value="2" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top"
                               Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle" Value="{StaticResource IconListCell}"/>
    </Style>
</ResourceDictionary>